

package com.hazelcast.client.impl.protocol.codec.custom;

import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.client.impl.protocol.Generated;
import com.hazelcast.client.impl.protocol.codec.builtin.ListMultiFrameCodec;

import static com.hazelcast.client.impl.protocol.ClientMessage.BEGIN_FRAME;
import static com.hazelcast.client.impl.protocol.ClientMessage.END_FRAME;
import static com.hazelcast.client.impl.protocol.codec.builtin.CodecUtil.fastForwardToEndFrame;

@SuppressWarnings("unused")
@Generated("9b58f0056a58d038b71695e621356055")
public final class RaftGroupInfoCodec {

    private RaftGroupInfoCodec() {
    }

    public static void encode(ClientMessage clientMessage, com.hazelcast.cp.internal.RaftGroupInfo raftGroupInfo) {
        clientMessage.add(BEGIN_FRAME.copy());

        RaftGroupIdCodec.encode(clientMessage, raftGroupInfo.getGroupId());
        CPMemberCodec.encode(clientMessage, raftGroupInfo.getLeader());
        ListMultiFrameCodec.encode(clientMessage, raftGroupInfo.getFollowers(), CPMemberCodec::encode);

        clientMessage.add(END_FRAME.copy());
    }

    public static com.hazelcast.cp.internal.RaftGroupInfo decode(ClientMessage.ForwardFrameIterator iterator) {
        // begin frame
        iterator.next();

        com.hazelcast.cp.internal.RaftGroupId groupId = RaftGroupIdCodec.decode(iterator);
        com.hazelcast.cp.internal.CPMemberInfo leader = CPMemberCodec.decode(iterator);
        java.util.Collection<com.hazelcast.cp.CPMember> followers = ListMultiFrameCodec.decode(iterator, CPMemberCodec::decode);

        fastForwardToEndFrame(iterator);

        return new com.hazelcast.cp.internal.RaftGroupInfo(groupId, leader, followers);
    }
}
